package com.zhihui.client.alarm.service.impl;

import com.zhihui.client.alarm.common.Lay;
import com.zhihui.client.alarm.common.Msg;
import com.zhihui.client.alarm.dao.AlarmvideoMapper;
import com.zhihui.client.alarm.entity.Alarmvideo;
import com.zhihui.client.alarm.service.AlarmvideoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 服务实现
 * @author zhihuian
 * @email 18037017565@163.com
 * @date 2018/10/29
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class AlarmvideoServiceImpl implements AlarmvideoService {
    @Resource
    private AlarmvideoMapper alarmvideoMapper;

    @Override
    public Msg addAlarmvideo(Alarmvideo alarmvideo) {
        int i=  alarmvideoMapper.insert(alarmvideo);
        Msg msg=new Msg();
        if (i>0){
            msg.setMsg("添加成功");
        }else{
            msg.setCode(-1);
            msg.setMsg("添加失败");
        }
        return msg;
    }

    @Override
    public Msg updateAlarmvideo(Alarmvideo alarmvideo) {
        int i= alarmvideoMapper.updateByParam(alarmvideo);
        Msg msg=new Msg();
        if (i>0){
            msg.setMsg("修改成功");
        }else{
            msg.setCode(-1);
            msg.setMsg("修改失败");
        }
        return msg;
    }

    @Override
    public Msg delAlarmvideo(Alarmvideo alarmvideo) {
        int i=alarmvideoMapper.del(alarmvideo.getAvidid());
        Msg msg=new Msg();
        if (i>0){
            msg.setMsg("删除成功");
        }else{
            msg.setCode(-1);
            msg.setMsg("删除失败");
        }
        return msg;
    }

    @Override
    public Lay getAlarmvideos(Alarmvideo alarmvideo, Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<Alarmvideo> alarmvideos=alarmvideoMapper.list(alarmvideo);
        PageInfo info=new PageInfo(alarmvideos);
        Lay lay=new Lay();
        lay.setPage(page);
        lay.setCount(info.getTotal());
        lay.setData(info.getList());
        return lay;
    }
}
